package com.newear.happyDialog;

import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.newear.R;

/**
 * Created by happy on 2018/5/27.
 */

public class CamaraCheckDialog extends AlertDialog {
    private Context mContext;
    private Button takePhotoBtn;
    private TextView mTextViewMain;
    private TextView mTexTViewSub;
    private String mTitleMain;
    private String mTitleSub;
    private int type = 1;
    public interface Type {
        int FACE = 1;
        int TONGUE =2;
        int REQUESTION = 3;
        int CAMRA_FACE = 4;
    }

    public CamaraCheckDialog(Context context, int themeResId, String titleMain, String titleSub, int type) {
        super(context, themeResId);
        mContext = context;
        mTitleMain = titleMain;
        mTitleSub = titleSub;
        this.type = type;
        //点击外面不允许消失,包括返回键
        setCanceledOnTouchOutside(false);
        setCancelable(false);
        //不加这一句的话,dialog不居中,在新时代大屏上
        getWindow().getAttributes().gravity = Gravity.CENTER;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.happy_camara_check_layout);
        mTextViewMain = (TextView) findViewById(R.id.tv_camera_des);
        mTexTViewSub = (TextView) findViewById(R.id.tv_camera_des_under);
        takePhotoBtn =  (Button) findViewById(R.id.btn_take_photo);
        if (type == Type.FACE) {
            takePhotoBtn.setText("去面诊");
        } else if (type == Type.TONGUE) {
            takePhotoBtn.setText("去舌诊");
        } else if ((type == Type.REQUESTION)){
            takePhotoBtn.setText("去问诊");
        } else if (type == Type.CAMRA_FACE){
            takePhotoBtn.setText("拍照");
        } else {
            takePhotoBtn.setText("确定");
        }
        takePhotoBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CamaraCheckDialog.this.dismiss();
                if (listener != null){
                    listener.takePhotoClickListener();
                }
            }
        });

        mTextViewMain.setText(mTitleMain);
        mTexTViewSub.setText(mTitleSub);
    }


    OnTakePhotoClickListener listener;

    public interface OnTakePhotoClickListener{
        void takePhotoClickListener();
    }

    public void setOnTakePhotoClickListener(OnTakePhotoClickListener listener){
        this.listener = listener;
    }



}
